package com.ddwl.user.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.common.util.MySqlUtil;
import com.ddwl.schema.bo.user.UpgradeAgentPageBo;
import com.ddwl.user.dao.mapper.UpgradeAgentOrderMapper;
import com.ddwl.user.model.UpgradeAgentOrder;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.time.Instant;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2021/9/23 18:28
 */
@Repository
public class UpgradeAgentOrderDao extends TkDao<UpgradeAgentOrderMapper, UpgradeAgentOrder> {

    public UpgradeAgentOrder queryExistOrder(String userId, Integer agentType,String superior) {
        Example example = getExample();
        example.and().andEqualTo("userId", userId)
                .andEqualTo("superior",superior)
                .andEqualTo("agentType", agentType)
                .andLessThan("expirationTime", Instant.now());
        example.setOrderByClause(" gmt_Created desc limit 1 ");
        return baseMapper.selectOneByExample(example);
    }

    public List<UpgradeAgentOrder> findList(UpgradeAgentPageBo param) {
        Example example = getExample();
        example.and().andEqualTo("agentType", param.getAgentType())
                .andEqualTo("sendStatus", param.getSendStatus())
                .andLessThan("userName", MySqlUtil.rightLike(param.getUserName()));
        return baseMapper.selectByExample(example);
    }
}
